<template>
    <div class="box2">
        <div class="title">
            <p>年龄比例</p>
            <img src="../../images/dataScreen-title.png" alt="">
        </div>
        <!-- 图形图标的容器 -->
        <div class="charts" ref="charts"></div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
//引入echarts
import * as echarts from 'echarts';
let charts = ref();
//组件挂载完毕初始化图形图标
onMounted(() => {
    let mychart = echarts.init(charts.value);
    //设置配置项
    let option = {
        tooltip: {
            trigger: 'item'
        },
        legend: {
            show: false,
            right: 0,
            top: 0,
            orient: 'vertical',//图例组件方向的设置
            textStyle: {
                color: 'white',
                fontSize: 14
            }
        },
        series: [
            {
                name: '年龄比例结构',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: true,
                    // position: 'inside',
                    position: 'outer',
                    color: 'white',
                    fontSize: 15
                },

                labelLine: {
                    show: true
                },
                data: [
                    { value: 1048, name: '10岁以下' },
                    { value: 735, name: '12~18岁' },
                    { value: 580, name: '20~30岁' },
                    { value: 484, name: '30~45岁' },
                    { value: 300, name: '45岁以上' }
                ]
            }
        ],
        //调整图形图标的位置
        // grid: {
        //     left: 0,
        //     top: 0,
        //     right: 0,
        //     bottom: 0
        // }
    };
    mychart.setOption(option);
});
</script>

<style scoped lang="scss">
.box2 {
    width: 100%;
    height: 100%;
    background: url(../../images/dataScreen-main-cb.png) no-repeat;
    background-size: 100% 100%;
    margin-top: 8px;
    padding: 10px 20px 0;

    .title {

        p {
            color: white;
            font-size: 20px;
        }
    }

    .charts {
        height: 260px;
    }

}
</style>